package com.zhangxiaofanfan.hotcode.second;

/**
 * <a href="https://leetcode.cn/problems/container-with-most-water/?envType=study-plan-v2&envId=top-100-liked">盛最多水的容器</a>
 *
 * @author zhangxiaofanfan
 * @date 2024-05-21 23:06:51
 */
public class HotCode005 {
    public static void main(String[] args) {
        int[] height = {1,8,6,2,5,4,8,3,7};
        HotCode005 hotCode = new HotCode005();
        System.out.println(hotCode.maxArea(height));
    }

    public int maxArea(int[] height) {
       int left = 0, right = height.length - 1;
       int area = Math.min(height[left], height[right]) * (right - left);

       while (left < right) {
           area = Math.max(area, Math.min(height[left], height[right]) * (right - left));
           if (height[left] < height[right]) {
               left++;
           } else {
               right--;
           }
       }

       return area;
    }
}
